package com.pachong.android.frameworkbase.dialog.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;


import com.pachong.android.frameworkbase.R;

/**
 * Alert Dialog Fragment
 *
 * @Author: PengWeiwei
 * @E-mail: pengveivei@sina.cn
 * @CreateDate: 2016-06-21
 * @Version: 1.0.0
 */
public abstract class IOSAlertBaseFragment extends BottomDialogFragment{

    private Button mBtnCancel;
    private CharSequence mCancelBtnText;
    private View.OnClickListener mCancelBtnListener;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_ios_alert_base, null);
        mBtnCancel = (Button) view.findViewById(R.id.btnCancel);
        LinearLayout lytContent = (LinearLayout) view.findViewById(R.id.lytContent);
        lytContent.addView(createDialogContentView(inflater));


        if (!TextUtils.isEmpty(mCancelBtnText)) {
            mBtnCancel.setText(mCancelBtnText);
        }

        if (mCancelBtnListener == null) {
            mCancelBtnListener = new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            };
        }

        mBtnCancel.setOnClickListener(mCancelBtnListener);
        return view;
    }

    public abstract View createDialogContentView(LayoutInflater inflater);


    public IOSAlertBaseFragment setCancelButton(CharSequence text, View.OnClickListener listener) {
        mCancelBtnListener = listener;
        mCancelBtnText = text;
        return this;
    }

    public IOSAlertBaseFragment setCancelButton(@StringRes int strId, View.OnClickListener listener) {
        return setCancelButton(getString(strId), listener);
    }

    public IOSAlertBaseFragment setCancelButton(@StringRes int strId) {
        return setCancelButton(getString(strId), null);
    }

    public IOSAlertBaseFragment setCancelButton(CharSequence text) {
        return setCancelButton(text, null);
    }

}
